<?php
namespace app\api\validate;
use app\common\model\ShopConfig;
use think\Db;
use think\Validate;

class Recharge extends Validate{
    protected $rule = [
        'id'        => 'checkRecharge',
        'money'     => 'checkRecharge'
    ];
    protected $message = [
    ];
    protected function checkRecharge($value,$rule,$data){
        if(empty($value) && $data['money']){
            return '请输入充值金额';
        }
        if($data['template_id']){
            $remplate = Db::name('recharge_template')
                        ->where(['id'=>$data['template_id'],'delete_time'=>0])
                        ->find();
            
            if(empty($remplate)){
                return '该充值模板不存在';
            }
        }else{
            $min_money = ShopConfig::get('recharge', 'min_money');
            if($data['money'] < $min_money){
                return '最低充值金额为'.$min_money;
            }
        }
        return true;
    }
}